package cm.controller;

import cm.DTO.UserDTO;
import cm.aoplog.annotations.OperateLog;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import cm.utils.ThreadPoolUtils;

import static cm.aoplog.enums.OperateTypeEnum.EXPORT;

/**
 * @author: yxh
 * @Description: 数据脱敏测试
 * @Date: Created in 2022/8/29 11:12
 * @Modified By:
 */
@RestController
@RequestMapping("/test")
public class SensitiveController {

    @Autowired
    @Qualifier(value = "taskExecutor")
    private ThreadPoolTaskExecutor poolTaskExecutor;



    @GetMapping ("/getUser")
    public UserDTO getUser() {
        UserDTO user = new UserDTO();
        user.setId(1L);
        user.setAge(18);
        user.setName("帆帆");
        user.setEmail("ff@163.com");
        poolTaskExecutor.execute(()-> System.err.println("线程池测试"));
        return user;
    }

    /**
     * 调用配置线程池
     */
    @PostMapping("/threadPoolConfig")
    @ApiOperation("线程")
    public void threadPoolConfig() {
        poolTaskExecutor.execute(()-> System.err.println("线程池测试"));
        poolTaskExecutor.execute(()-> System.err.println(poolTaskExecutor.getCorePoolSize()));
    }

    /**
     * 调用工具类线程池
     */
    @PostMapping("/threadPoolUtil")
    public void threadPoolUtil() {
        ThreadPoolUtils.getPool().execute(()-> System.err.println("工具类线程池"));
    }

    @GetMapping("/exportTest")
    @ApiOperation("测试数据")
    @OperateLog(type = EXPORT)
    public void export() {
        System.err.println("测试");
    }
}
